package com.myhexin.demo.ruleengine;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;

public class QLExpressExample2 {

    public static void main(String[] args) {
        try {
            ExpressRunner runner = new ExpressRunner();
            DefaultContext<String, Object> context = new DefaultContext<>();

            // 设置变量
            context.put("a", 10);
            context.put("b", 5);

            // 算术运算示例
            QLExpressUtil.executeAndPrint(runner, context, "a + b", "Addition");

            // 比较运算示例
            QLExpressUtil.executeAndPrint(runner, context, "a > b", "Greater than");

            // 逻辑运算示例
            QLExpressUtil.executeAndPrint(runner, context, "a > 0 && b > 0", "Logical AND");

            // 三元运算示例
            QLExpressUtil.executeAndPrint(runner, context, "a > b ? 'a is greater' : 'b is greater'", "Ternary Operator");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
